#include "stm32f10x.h"
#include "uart.h"
#include "stdio.h"
#include "sys.h"
#include "iap.h"
#include "string.h"
#include "ymodem.h"

unsigned char serial_buff[128] = { 0 };


int main(void)
{
    uart_init(115200);
    printf("STM32 IAP SOFTWARE_VERSION:0x%x\n", SOFTWARE_VERSION);
	printf("Commond:\n-reset\n-erase\n-update\n");
	
	
    while (1) {
        GetInputString(serial_buff);

        if (strcmp((char*)serial_buff, "reset") == 0) {
            printf("system reset\n");
            NVIC_SystemReset();
        }
        else if (strcmp((char*)serial_buff, "erase") == 0) {
            printf("iap earse\n");
            IAP_Erase();
        }
        else if (strcmp((char*)serial_buff, "update") == 0) {
            printf("iap update\n");
            if (!IAP_Update()) {
                printf("update suc\n");
                delay_ms(2000);
            }
            IAP_RunApp();
        }

        memset(serial_buff, '\0', sizeof(serial_buff));
    }
}

